<?php
/**
 * 如何获取PDOStatement->excute()的执行错误信息？
 * 使用PDOStatement->errorInfo()获取
 */
$dsn = "mysql:host=localhost;dbname=lab10";
try{
	$pdo = new PDO($dsn, "root", "123456");
	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e){
	echo $e->getMessage();
}

$sql = "insert into students values(:stuId, :stuName, :stuPwd, :stuCourse, :stuGender);";

$stmt = $pdo->prepare($sql);
$stuId = 12;
$stuName = "12312";
$stuPwd = "123123";
$course = "123";
$gender = "123";
$stmt->bindParam(':stuId', $stuId);
$stmt->bindParam(':stuName', $stuName);
$stmt->bindParam(':stuPwd', $stuPwd);
$stmt->bindParam(':stuCourse', $course);
$stmt->bindParam(':stuGender', $gender);
try{
	$stmt->execute();
	//var_dump($stmt->errorInfo());
}
catch (PDOException $e){
	//echo $e->getMessage();
}